package sz.szsmk.citizencard.ui.adapter;

import android.content.Context;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

import sz.szsmk.citizencard.R;
import sz.szsmk.citizencard.model.network.bean.response.QueryDonationRes;

/**
 * Copyright (c)2019
 * author: zdh
 * created on: 2019/1/5 15:19
 * description:
 */
public class DonationItemAdapter extends RecyclerView.Adapter<DonationItemAdapter.DonationItemHolder> {
    private Context mContext;
    private List<QueryDonationRes.CommonwealOrdersBean.RecordInforsBean> viewData;

    public DonationItemAdapter(Context mContext) {
        this.mContext = mContext;
    }

    @Override
    public DonationItemHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.donation_item_view, parent, false);
        return new DonationItemHolder(view);
    }

    @Override
    public void onBindViewHolder(DonationItemHolder holder, int position) {
        if (viewData != null) {
            QueryDonationRes.CommonwealOrdersBean.RecordInforsBean inforsBean = viewData.get(position);
            double totalMoney = (double) inforsBean.getCommonwealMoney() / 100;
            holder.donationMoney.setText(totalMoney+"元");
            holder.donationName.setText(inforsBean.getCommonwealUserName());
            holder.donationOrder.setText(inforsBean.getOrderNo());
            holder.donationTime.setText(inforsBean.getCreateTime());
        }
    }

    @Override
    public int getItemCount() {
        return null == viewData ? 0 : viewData.size();
    }

    public void setViewData(List<QueryDonationRes.CommonwealOrdersBean.RecordInforsBean> viewData) {
        this.viewData = viewData;
    }

    public static class DonationItemHolder extends RecyclerView.ViewHolder {

        private final TextView donationTime;
        private final TextView donationMoney;
        private final TextView donationName;
        private final TextView donationOrder;

        public DonationItemHolder(View itemView) {
            super(itemView);
            donationTime = (TextView) itemView.findViewById(R.id.donation_view_time);
            donationMoney = (TextView) itemView.findViewById(R.id.donation_view_money);
            donationName = (TextView) itemView.findViewById(R.id.donation_view_name);
            donationOrder = (TextView) itemView.findViewById(R.id.donation_view_order);
        }
    }

}
